#ifndef _MEMORY_ALLOCATOR
#define _MEMORY_ALLOCATOR

template<typename T>
class DLL_EXPORT ScopedAllocator
{
	T* datachunk;
	size_t thesize;
public:
	// Keep in mind, that desiredsz is meant as arraysize, not bytesize!
	ScopedAllocator(size_t desiredsz) : thesize(desiredsz)
	{
		datachunk = new T[desiredsz];
	}

	// Note: does not call constructors of new elements if newsize > oldsize
	// Keep in mind, that newsize is meant as arraysize, not bytesize!
	void Resize(size_t newsize)
	{
		realloc((void*)datachunk, sizeof(T) * newsize);
		thesize = newsize;
	}

	~ScopedAllocator()
	{
		delete [] datachunk;
	}

	template<typename P>
	operator P()
	{
		assert(sizeof(P) == sizeof(unsigned long));
		return (P)datachunk;
	}

	T& operator[](size_t index)
	{
		assert(index < thesize);
		return *(datachunk + index);
	}
	
	static void* operator new(size_t)
	{
		throw("Do not use pointers of ScopedAllocators! (Occured in: \""__FILE__"\" on line: "__LINE__")");
	}

	static void* operator new[](size_t)
	{
		throw("Do not use pointers of ScopedAllocators! (Occured in: \""__FILE__"\" on line: "__LINE__")");
	}

	T* operator+(size_t amt)
	{
		assert(amt < thesize);
		return datachunk + amt;
	}
};

#endif